package com.swotxu.oldwebproject.web.controller;

import com.swotxu.oldwebproject.web.pojo.UserInfo;
import com.swotxu.oldwebproject.web.pojo.WebResult;
import com.swotxu.oldwebproject.web.service.LoginService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登陆入口
 *
 * @Date: 2019/12/16 21:53
 * @Author: swotXu
 */
@Controller
@RequestMapping("/login")
public class LoginController {
    private static final Logger log = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private LoginService loginService;

    @GetMapping("/toLogin")
    public String toLogin(){
        log.info("/toLogin");
        return "modules/login/login";
    }

    @RequestMapping("/login")
    @ResponseBody
    public WebResult login(@RequestBody UserInfo userInfo, HttpServletRequest request){
        log.info("/login");
        return loginService.login(userInfo, request);
    }

    @RequestMapping("/outLogin")
    public void outLogin(HttpServletRequest request, HttpServletResponse response){
        log.info("/outLogin");
        loginService.outLogin(request, response);
    }

    @RequestMapping("/toError")
    public String toError(){
        log.info("/toError");
        return "modules/error/error";
    }
}
